﻿using System;
namespace Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="SorditavVali", Namespace="http://producers.etoimik.xtee.riik.ee/producer/etoimik", Target=typeof(SorditavVali))]
    public class SorditavValiSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected ISorditavVali clazz;
        
        public SorditavValiSerializer(ISorditavVali clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (clazz.SortField!=null) {
                Writer.WriteStartElement("SortField");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.SortField))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.SortOrder!=null) {
                Writer.WriteStartElement("SortOrder");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "long");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdLong(((long)(clazz.SortOrder))).ToString());
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="SortField") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.SortField = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("SortField")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="SortOrder") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>SorditavVali>SortOrder");
                }
                clazz.SortOrder = new global::Xtee.Core.Schema.XsdLong(Reader.ReadElementString("SortOrder")).Value;
            }
        }
    }
}
